package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.system.domain.TPurchase;
import com.ruoyi.system.service.ITPurchaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 *
 * @date 2021-03-24
 */
@Controller
@RequestMapping("/system/purchase")
public class TPurchaseController extends BaseController
{
    private String prefix = "system/purchase";

    @Autowired
    private ITPurchaseService tPurchaseService;

    @GetMapping()
    public String purchase()
    {
        return prefix + "/purchase";
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TPurchase tPurchase)
    {
        startPage();
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPurchase tPurchase)
    {
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        ExcelUtil<TPurchase> util = new ExcelUtil<TPurchase>(TPurchase.class);
        return util.exportExcel(list, "purchase");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.insertTPurchase(tPurchase));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{purchaseId}")
    public String edit(@PathVariable("purchaseId") Long purchaseId, ModelMap mmap)
    {
        TPurchase tPurchase = tPurchaseService.selectTPurchaseById(purchaseId);
        mmap.put("tPurchase", tPurchase);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.updateTPurchase(tPurchase));
    }

    /**
     * 删除
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tPurchaseService.deleteTPurchaseByIds(ids));
    }
}